package error

func dynamic(height []int) int {
	//使用动态规划
	result := 0
	//dp[i][j]表示i到j之间的最大可容纳的水
	dp := make([][]int, len(height))
	for i := 0; i < len(height); i++ {
		dp[i] = make([]int, len(height))
	}

	dp[0][0] = 0
	//dp[i][j]=max(dp[i][j-1],(j-i)*min(height[i],height[j]))
	for i := 0; i < len(height); i++ {
		for j := i + 1; j < len(height); j++ {
			dp[i][j] = max(dp[i][j-1], (j-i)*min(height[i], height[j]))
			result = max(result, dp[i][j])
		}
	}

	return result
}
